# from wxauto import new_wxauto
from new_wxauto import *
import requests
import time
import re
import os
import shutil
# from urllib.request import urlretrieve
import urllib.request
from urllib.parse import quote
import string
# 获取当前微信客户端
wx = WeChat()

# 获取会话列表
wx.GetSessionList()




## 发送换行消息（最近很多人问换行消息如何发送，新增说明一下）
# msg = '''你好
# 这是第二行
# 这是第三行
# 这是第四行'''
# who = '文件传输助手'
# WxUtils.SetClipboard(msg)  # 将内容复制到剪贴板，类似于Ctrl + C
# wx.ChatWith(who)  # 打开`文件传输助手`聊天窗口
# wx.SendClipboard()  # 发送剪贴板的内容，类似于Ctrl + V

def getMsg(who):
    wx.ChatWith(who)  # 打开`文件传输助手`聊天窗口
    # 输出当前聊天窗口聊天消息
    forMsg()    
    ## 获取更多聊天记录
    wx.LoadMoreMessage()
    forMsg()    

def forMsg():
    msgs = wx.GetAllMessage
    for msg in msgs:
        actual_nick_name_req = re.search(r'丁文|浅水|张新梓|侠义|盈婷老师|陈菊芬13566075791|春天细雨|吴启浙|Monica.|飞燕|缘来是你|朱..萍', msg[0])
        if (str(actual_nick_name_req) == 'None'):
            print('%s : %s' % (msg[0], msg[1]))

locale_txt = {"txt": "", "dateTime": time.time(), "count": 1,"msgCount": 1, "loop_time": time.time()}
def record_txt(*args):
    msg_text = args[1].strip()
    locale_text = locale_txt["txt"]
    count = time.time() - locale_txt["dateTime"]
    num_reg = re.search(r'\d{2,4}', msg_text)
    male_reg = re.search(r'(男|女)', msg_text)
    keyword_not_in_reg = re.search(r'有没有|引用|- - -|@|接龙|东钱湖万金社区|公益|义务|相亲', msg_text)
    phone_reg = re.search(r'(((13[0-9]{1})|(14[57]{1})|(15[012356789]{1})|(17[03678]{1})|(18[0-9]{1})|(19[89]{1})|(16[6]{1}))+\d{8})', msg_text)

    if str(num_reg) != 'None' and str(male_reg) != 'None' and str(keyword_not_in_reg) == 'None' and str(phone_reg) == 'None' and len(msg_text) > 80 and len(msg_text) < 350:
        if count > 60 * 60 * 12 : #count值为秒  12小时
            locale_txt["txt"] = ""
            locale_txt["dateTime"] = time.time()
            locale_txt["msgCount"] = 1
        if msg_text not in locale_text:
            locale_txt["txt"] = locale_text+msg_text
            return True
        else:
            return False
    else:
         return False


# forever = 2
# while forever%2==0:
#     getMsg('房产中介对接群')
#     time.sleep(100) # second

msg = '''你好
这是第二行
这是第三行
这是第四行'''
who = '房产中介对接群'
wx.ChatWith(who)  # 打开`文件传输助手`聊天窗口
WxUtils.SetClipboard(msg)  # 将内容复制到剪贴板，类似于Ctrl + C
wx.SendClipboard()  # 发送剪贴板的内容，类似于Ctrl + V


# def send_at_time(message, receiver):
#     while True:
#         wx.SendMsg(message, receiver)
#         time.sleep(50)

# send_at_time('ads', '房产中介对接群')